package com.zy.domain;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component//默认为类名首字母小写
@Scope("singleton")
public class Person
{
    @Value("zahngsan")
    private String name;
    private Integer age;

    @Autowired//复杂类型的依赖注入，自动注入
    @Qualifier("benchi")
    //使用@Resource(name="baoma")代替上面
    private Car car;

    public Person()
    {
        System.out.println("Person对象产生了");
    }

    public Person(String name, Integer age, Car car)
    {
        this.name = name;
        this.age = age;
        this.car = car;
    }

    @PostConstruct
    public void init()
    {
        System.out.println("init方法被调用-----");
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Integer getAge()
    {
        return age;
    }

    public void setAge(Integer age)
    {
        this.age = age;
    }

    public Car getCar()
    {
        return car;
    }

    public void setCar(Car car)
    {
        this.car = car;
    }

    @Override
    public String toString()
    {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", car=" + car +
                '}';
    }

    @PreDestroy
    public void destroy()
    {
        System.out.println("destroy方法被调用----");
    }

}
